<?php

namespace app\common\model\other;
use think\Model;
class Notice extends Model
{




    // 表名
    protected $name = 'notice';


    public function getCreatetimeAttr($value)
    {
        $status = date('Y-m-d', $value);
        return $status;
    }


    /**
     * 读取分类列表
     * @param string $type   指定类型
     * @param string $status 指定状态
     * @return array
     */
    public static function getListfa()
    {

        $list['notice']=collection(self::where(['type'=>10,'status'=>'normal'])->limit(15)->field('id,title,createtime,image,description,weigh,show_number,type')->order(['weigh'=>'desc','createtime'=>'desc'])->select())->toArray();
        $list['tell']=collection(self::where(['type'=>20,'status'=>'normal'])->limit(15)->field('id,title,createtime,image,description,weigh,show_number,type')->order(['weigh'=>'desc','createtime'=>'desc'])->select())->toArray();
        $list['publicity']=collection(self::where(['type'=>30,'status'=>'normal'])->field('id,title,createtime,image,description,weigh,show_number,type')->order(['weigh'=>'desc','createtime'=>'desc'])->select())->toArray();

        return $list;
    }

    /**
     * 读取分类列表
     * @param string $type   指定类型
     * @param string $status 指定状态
     * @return array
     */
    public static function getList()
    {

        $list['notice']=collection(self::where(['type'=>10,'status'=>'normal'])->field('id,title,createtime,image,description,weigh,show_number,type')->order(['weigh'=>'desc','createtime'=>'desc'])->select())->toArray();
        $list['tell']=collection(self::where(['type'=>20,'status'=>'normal'])->field('id,title,createtime,image,description,weigh,show_number,type')->order(['weigh'=>'desc','createtime'=>'desc'])->select())->toArray();
        $list['publicity']=collection(self::where(['type'=>30,'status'=>'normal'])->field('id,title,createtime,image,description,weigh,show_number,type')->order(['weigh'=>'desc','createtime'=>'desc'])->select())->toArray();

        return $list;
    }
    /**
     * 读取分类列表
     * @param string $type   指定类型
     * @param string $status 指定状态
     * @return array
     */
    public static function suspensionnotice()
    {

        $list=self::where(['status'=>'normal','is_home_show'=>1])->order(['weigh'=>'desc','createtime'=>'desc'])->find();
        return $list;
    }
    /*
    * 读取分页
    * @param string $type   指定类型
    * @param string $status 指定状态
    * @return array
    */
    public static function getListpage($data)
    {

        $list=self::where(['type'=>$data['type'],'status'=>'normal'])->field('id,title,createtime,image,description,weigh,show_number,type')->order(['weigh'=>'desc','createtime'=>'desc'])->paginate(15,false,['page'=>$data['page']]);
        return $list;
    }


    /*
    * 读取分页
    * @param string $type   指定类型
    * @param string $status 指定状态
    * @return array
    */
    public static function details($id)
    {

        $list=self::where(['id'=>$id,'status'=>'normal'])->find();
        $list->setInc('show_number',1);
        return $list;
    }

}
